var util = require('../../libs/util.js');
var app = getApp();
Page({
  data: {
    index: '',
    price: 0,
    distance: 0,
    incomeService: {
      income: 180,
      mile: 0,
      backmile: 0,
      shopReward: 0,
      stevedoreReward: 0,
      overtimeReward: 0
    }
  },
  onShareAppMessage: function () {
    return {
      title: app.appName,
      path: '/pages/index/index'
    }
  },
  onLoad: function (e) {
    wx.setNavigationBarTitle({ "title": app.appName +"--计价规则详情" });
    this.setData({
      index: e.index,
      price: e.price,
      distance: e.distance,
      point: e.point,
      incomeService: {
        startPrice: 180,
        mile: (Number(e.distance) - 5) * 7,
        backmile: Number(e.distance) * 7 * 0.4,
        shopReward: Number(e.point) * 30,
        stevedoreReward: 0,
        overtimeReward: 0
      }
    });
    wx.removeStorage({
      key: 'warehouseConfig',
      success: function (res) {
      }
    });
  },
  onReady: function () {
    wx.hideToast()
  },
  bindInput: function (e) {
    var item = String(e.currentTarget.id), item_value = {};
    item_value[item] = e.detail.value;
    this.setData(item_value);
  },
  confirmData: function () {
    wx.setStorage({
      key: "warehouseConfig",
      data: { delivery_date: this.data.delivery_date, loading_time: this.data.loading_time, depart_time: this.data.depart_time }
    });
    if (!this.data.delivery_date || !this.data.loading_time || !this.data.depart_time) {
      wx.showToast({
        title: "有未输入项",
        image: "/images/wrong.svg",
        duration: 3000
      });
      return false;
    }
  },
  cancelConfirmData: function () {
    wx.navigateBack({
      delta: 1
    });
  }
});